package com.tianya.controller;

import com.tianya.common.Results;
import com.tianya.domain.dto.ExamRequestDTO;
import com.tianya.domain.entity.Exam;
import com.tianya.domain.vo.ExamVO;
import com.tianya.domain.vo.PageResultVO;
import com.tianya.service.ExamService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author TianYaGuoKe
 * @date 2025/5/26 13:15
 * @description ExamController
 */
@Api("考试管理")
@RestController
@RequestMapping("/exam")
public class ExamController {

    @Resource
    private ExamService examService;

    @ApiOperation("创建考试")
    @PostMapping
    public Results createExam(@RequestBody ExamRequestDTO examRequestDTO) {
        examService.createExam(examRequestDTO);
        return Results.success();
    }

    @ApiOperation("根据班级id获取考试信息")
    @GetMapping("/student/{clazzId}")
    public Results<List<ExamVO>> getExamByClazzId(@RequestParam Long clazzId) {
        return Results.success(examService.getExamByClazzId(clazzId));
    }
    @ApiOperation("获取所有考试")
    @GetMapping("/list")
    public Results<List<ExamVO>> listExam() {
        return Results.success(examService.listExam());
    }
    @ApiOperation("分页获取考试")
    @PostMapping("/page")
    public Results<PageResultVO<ExamVO>> pageExam(@RequestParam(defaultValue = "1") Integer pageNum,
                                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                                  ExamRequestDTO examRequestDTO) {
        return Results.success(examService.pageExam(pageNum, pageSize, examRequestDTO));
    }

    @ApiOperation("查看详情")
    @GetMapping("/{id}")
    public Results<ExamVO> getExam(@PathVariable Long id) {
        return Results.success(examService.getDetail(id));
    }

    @ApiOperation("编辑考试")
    @PutMapping
    public Results updateExam(@RequestBody Exam exam) {
        examService.updateById(exam);
        return Results.success();
    }

    @ApiOperation("删除考试")
    @DeleteMapping("/{id}")
    public Results deleteExam(@PathVariable Long id) {
        examService.removeById(id);
        return Results.success();
    }
}
